package com.pphh.demo;

import com.pphh.demo.exception.BlockException;

import java.util.concurrent.*;

/**
 * Please add description here.
 *
 * @author huangyinhuang
 * @date 11/21/2018
 */
public class ThreadPoolFlowControl extends FlowControl {

    private ExecutorService executorService = new ThreadPoolExecutor(
            0, 5,
            1000, TimeUnit.MILLISECONDS,
            new SynchronousQueue<>());


    @Override
    public void run() throws BlockException {
        try {
            // execute the test task
            Future future = this.executorService.submit(() -> test());
        } catch (Exception e) {
            throw new BlockException("task is blocked by thread pool.");
        }
    }

}
